Public Class cParcella
    Inherits Connessione

    Private _id As String
    Private _idIsc As String
    Private _numero As String
    Private _data As String
    Private _oggetto As String
    Private _numReg As String
    Private _dataPres As String
    Private _imponibile As String
    Private _diritti As String
    Private _dataPag As String
    Private _tipoPag As String


    Public Property id() As String
        Get
            Return _id
        End Get
        Set(ByVal Value As String)
            _id = Value
        End Set
    End Property
    Public Property idIsc() As String
        Get
            Return _idIsc
        End Get
        Set(ByVal Value As String)
            _idIsc = Value
        End Set
    End Property
    Public Property numero() As String
        Get
            Return _numero
        End Get
        Set(ByVal Value As String)
            _numero = Value
        End Set
    End Property
    Public Property data() As String
        Get
            Return _data
        End Get
        Set(ByVal Value As String)
            _data = Value
        End Set
    End Property
    Public Property oggetto() As String
        Get
            Return _oggetto
        End Get
        Set(ByVal Value As String)
            _oggetto = Value
        End Set
    End Property
    Public Property numReg() As String
        Get
            Return _numReg
        End Get
        Set(ByVal Value As String)
            _numReg = Value
        End Set
    End Property
    Public Property dataPres() As String
        Get
            Return _dataPres
        End Get
        Set(ByVal Value As String)
            _dataPres = Value
        End Set
    End Property
    Public Property imponibile() As String
        Get
            Return _imponibile
        End Get
        Set(ByVal Value As String)
            _imponibile = Value
        End Set
    End Property
    Public Property diritti() As String
        Get
            Return _diritti
        End Get
        Set(ByVal Value As String)
            _diritti = Value
        End Set
    End Property
    Public Property dataPag() As String
        Get
            Return _dataPag
        End Get
        Set(ByVal Value As String)
            _dataPag = Value
        End Set
    End Property
    Public Property tipoPag() As String
        Get
            Return _tipoPag
        End Get
        Set(ByVal Value As String)
            _tipoPag = Value
        End Set
    End Property

    Public Sub carica()
        Dim dr As DataRow = getDataTable("select Numero, convert(char(10),data,103) as data, Oggetto, NumReg, " & _
            "convert(char(10),DataPres,103) as DataPres, imponibile, Diritti, convert(char(10),Data_pag,103) as Data_pag, tipoPag FROM Parcelle where id=" & _id).Rows(0)

        _numero = dr("numero")
        _data = Utility.sNull(dr("data"))
        _oggetto = dr("oggetto")
        _numReg = dr("numReg")
        _dataPres = Utility.sNull(dr("dataPres"))
        _imponibile = Utility.numXvideo((dr("imponibile")))
        _diritti = Utility.numXvideo(dr("diritti"))
        _dataPag = Utility.sNull(dr("data_pag"))
        _tipoPag = Utility.sNull(dr("tipoPag"))

    End Sub

    Public Sub salva()
        If _id = "" Then
            inserisci()
        Else
            aggiorna()
        End If
    End Sub

    Private Sub inserisci()
        Dim sql As String = "insert into parcelle (idIscritto, numero, data, oggetto, numReg, dataPres, imponibile, diritti, data_pag, tipoPag, utente) " & _
                " values (@idIsc, @numero, @data, @oggetto, @numReg, @dataPres, @imponibile, @diritti, @dataPag, @tipoPag, @utente)"

        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(sql, getConnection)
        cmd.Parameters.Add("@idIsc", _idIsc)
        cmd.Parameters.Add("@numero", _numero)
        cmd.Parameters.Add("@data", IIf(_data = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_data)))
        cmd.Parameters.Add("@oggetto", _oggetto)
        cmd.Parameters.Add("@numReg", _numReg)
        cmd.Parameters.Add("@dataPres", IIf(_dataPres = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_dataPres)))
        cmd.Parameters.Add("@imponibile", IIf(_imponibile = "", SqlTypes.SqlInt64.Null, Utility.numXdb(_imponibile)))
        cmd.Parameters.Add("@diritti", IIf(_diritti = "", SqlTypes.SqlInt64.Null, Utility.numXdb(_diritti)))
        cmd.Parameters.Add("@dataPag", IIf(_dataPag = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_dataPag)))
        cmd.Parameters.Add("@tipoPag", IIf(_tipoPag = "", SqlTypes.SqlInt16.Null, _tipoPag))
        cmd.Parameters.Add("@Utente", System.Security.Principal.WindowsIdentity.GetCurrent.Name)
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

    End Sub

    Private Sub aggiorna()
        Dim sql As String = "update parcelle set numero=@numero, data=@data, oggetto=@oggetto, numReg=@numReg, dataPres=@dataPres, " & _
            " imponibile=@imponibile, diritti=@diritti, data_pag=@dataPag, tipoPag=@tipoPag, utente=@utente where id=" & _id

        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(sql, getConnection)
        cmd.Parameters.Add("@numero", _numero)
        cmd.Parameters.Add("@data", IIf(_data = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_data)))
        cmd.Parameters.Add("@oggetto", _oggetto)
        cmd.Parameters.Add("@numReg", _numReg)
        cmd.Parameters.Add("@dataPres", IIf(_dataPres = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_dataPres)))
        cmd.Parameters.Add("@imponibile", IIf(_imponibile = "", SqlTypes.SqlInt64.Null, Utility.numXdb(_imponibile)))
        cmd.Parameters.Add("@diritti", IIf(_diritti = "", SqlTypes.SqlInt64.Null, Utility.numXdb(_diritti)))
        cmd.Parameters.Add("@dataPag", IIf(_dataPag = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_dataPag)))
        cmd.Parameters.Add("@tipoPag", IIf(_tipoPag = "", SqlTypes.SqlInt16.Null, _tipoPag))
        cmd.Parameters.Add("@Utente", System.Security.Principal.WindowsIdentity.GetCurrent.Name)
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
    End Sub

    Public Sub elimina()
        eseguiSql("delete from parcelle where id = " & _id)
    End Sub
End Class


Public Class cIscrizione
    Inherits Connessione

    Private _id As String
    Private _idIsc As String
    Private _dal As String
    Private _al As String
    Private _numero As String
    Private _motivo As String
    Private _dataDel As String
    Private _numDel As String
    Private _sezione As String
    Private _albo As String
    Private _provAlbo As String
    Private _motivoCanc As String
    Private _note As String
    Private _sessione As String
    Private _settori As DataTable


    Public Property sessione() As String
        Get
            Return _sessione
        End Get
        Set(ByVal Value As String)
            _sessione = Value
        End Set
    End Property
    Public Property dataDel() As String
        Get
            Return _dataDel
        End Get
        Set(ByVal Value As String)
            _dataDel = Value
        End Set
    End Property
    Public Property numDel() As String
        Get
            Return _numDel
        End Get
        Set(ByVal Value As String)
            _numDel = Value
        End Set
    End Property
    Public Property motivoCanc() As String
        Get
            Return _motivoCanc
        End Get
        Set(ByVal Value As String)
            _motivoCanc = Value
        End Set
    End Property
    Public Property note() As String
        Get
            Return _note
        End Get
        Set(ByVal Value As String)
            _note = Value
        End Set
    End Property
    Public Property id() As String
        Get
            Return _id
        End Get
        Set(ByVal Value As String)
            _id = Value
        End Set
    End Property
    Public Property idIsc() As String
        Get
            Return _idIsc
        End Get
        Set(ByVal Value As String)
            _idIsc = Value
        End Set
    End Property
    Public Property dal() As String
        Get
            Return _dal
        End Get
        Set(ByVal Value As String)
            _dal = Value
        End Set
    End Property
    Public Property al() As String
        Get
            Return _al
        End Get
        Set(ByVal Value As String)
            _al = Value
        End Set
    End Property
    Public Property numero() As String
        Get
            Return _numero
        End Get
        Set(ByVal Value As String)
            _numero = Value
        End Set
    End Property
    Public Property motivo() As String
        Get
            Return _motivo
        End Get
        Set(ByVal Value As String)
            _motivo = Value
        End Set
    End Property
    Public Property sezione() As String
        Get
            Return _sezione
        End Get
        Set(ByVal Value As String)
            _sezione = Value
        End Set
    End Property
    Public Property albo() As String
        Get
            Return _albo
        End Get
        Set(ByVal Value As String)
            _albo = Value
        End Set
    End Property
    Public Property provAlbo() As String
        Get
            Return _provAlbo
        End Get
        Set(ByVal Value As String)
            _provAlbo = Value
        End Set
    End Property
    Public Property settori() As DataTable
        Get
            Return _settori
        End Get
        Set(ByVal Value As DataTable)
            _settori = Value
        End Set
    End Property


    Public Sub carica()
        Dim dr As DataRow = getDataTable("select convert(char(10),dal,103) as dal, " & _
            "convert(char(10),al,103) as  al, numero, motivo, sezione, albo, provAlbo, motivoCanc, note,  " & _
            "convert(char(10),data_delib,103) as data_delib, num_delib, sessione from IscrizioniStorico where id=" & _id).Rows(0)

        _dal = Utility.sNull(dr("dal"))
        _al = Utility.sNull(dr("al"))
        _numero = Utility.sNull(dr("numero"))
        _motivo = Utility.sNull(dr("motivo"))
        _sezione = Utility.sNull(dr("sezione"))
        _albo = Utility.sNull(dr("albo"))
        _provAlbo = Utility.sNull(dr("provAlbo"))
        _motivoCanc = Utility.sNull(dr("motivoCanc"))
        _dataDel = Utility.sNull(dr("data_delib"))
        _numDel = Utility.sNull(dr("num_delib"))
        _note = Utility.sNull(dr("note"))
        _sessione = Utility.sNull(dr("sessione"))
        _settori = getDataTable("SELECT Settori.codice, Settori.descrizione, convert(char(10), data, 103) as data FROM SettoriIscrizioniStorico INNER JOIN " & _
                        "Settori ON SettoriIscrizioniStorico.idSettore = Settori.codice WHERE SettoriIscrizioniStorico.idIscrizione =" & _id)
    End Sub

    Public Sub salva()
        If _id = "" Then
            _id = eseguiSPInsert("insertIscrizione")
        End If
        aggiorna()

    End Sub

    Private Sub aggiorna()
        Dim sql As String = "update iscrizioniStorico set idIscritto = @idIsc, dal=@dal, al=@al, numero=@numero, motivo=@motivo, sezione=@sezione, " & _
            "albo=@albo, provAlbo=@provAlbo, motivoCanc=@motivoCanc, note=@note, data_delib=@dataDel, num_delib=@numDel, utente=@utente, sessione=@sessione where id=" & _id
        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(sql, getConnection)
        cmd.Parameters.Add("@idIsc", _idIsc)
        cmd.Parameters.Add("@dal", IIf(_dal = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_dal)))
        cmd.Parameters.Add("@al", IIf(_al = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_al)))
        cmd.Parameters.Add("@numero", _numero)
        cmd.Parameters.Add("@motivo", IIf(_motivo = "", SqlTypes.SqlInt16.Null, _motivo))
        cmd.Parameters.Add("@sezione", _sezione)
        cmd.Parameters.Add("@albo", IIf(_albo = "", SqlTypes.SqlInt16.Null, _albo))
        cmd.Parameters.Add("@provAlbo", _provAlbo)
        cmd.Parameters.Add("@motivoCanc", IIf(_motivoCanc = "", SqlTypes.SqlInt16.Null, _motivoCanc))
        cmd.Parameters.Add("@note", _note)
        cmd.Parameters.Add("@dataDel", IIf(_dataDel = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_dataDel)))
        cmd.Parameters.Add("@numDel", _numDel)
        cmd.Parameters.Add("@Utente", System.Security.Principal.WindowsIdentity.GetCurrent.Name)
        cmd.Parameters.Add("@sessione", _sessione)
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

        eseguiSql("delete from SettoriIscrizioniStorico where idIscrizione =" & _id)

        Dim dr As DataRow
        For Each dr In _settori.Rows
            eseguiSql("insert into SettoriIscrizioniStorico (idIscrizione, idSettore, data) values(" & _id & ", " & dr("codice") & ", " & IIf(Utility.sNull(dr("data")) = "", "null", "'" & Utility.FormattaDataxDB(Utility.sNull(dr("data"))) & "'") & ")")
        Next



    End Sub

    Public Sub elimina()
        eseguiSql("delete from SettoriIscrizioniStorico where idIscrizione =" & _id)
        eseguiSql("delete from iscrizioniStorico where id=" & _id)
    End Sub
End Class

Public Class cSpecializzazione
    Inherits Connessione

    Private _id As String
    Private _idIsc As String
    Private _data As String
    Private _matricola As String
    Private _idIstituto As String
    Private _tipo As String
    Private _motivo As String
    Private _dataPub As String
    Private _requisiti As DataTable
    Private _note As String

    Public Property note() As String
        Get
            Return _note
        End Get
        Set(ByVal Value As String)
            _note = Value
        End Set
    End Property
    Public Property id() As String
        Get
            Return _id
        End Get
        Set(ByVal Value As String)
            _id = Value
        End Set
    End Property
    Public Property idIstituto() As String
        Get
            Return _idIstituto
        End Get
        Set(ByVal Value As String)
            _idIstituto = Value
        End Set
    End Property
    Public Property idIsc() As String
        Get
            Return _idIsc
        End Get
        Set(ByVal Value As String)
            _idIsc = Value
        End Set
    End Property
    Public Property data() As String
        Get
            Return _data
        End Get
        Set(ByVal Value As String)
            _data = Value
        End Set
    End Property
    Public Property matricola() As String
        Get
            Return _matricola
        End Get
        Set(ByVal Value As String)
            _matricola = Value
        End Set
    End Property
    Public Property tipo() As String
        Get
            Return _tipo
        End Get
        Set(ByVal Value As String)
            _tipo = Value
        End Set
    End Property
    Public Property motivo() As String
        Get
            Return _motivo
        End Get
        Set(ByVal Value As String)
            _motivo = Value
        End Set
    End Property
    Public Property dataPub() As String
        Get
            Return _dataPub
        End Get
        Set(ByVal Value As String)
            _dataPub = Value
        End Set
    End Property
    Public Property requisiti() As DataTable
        Get
            Return _requisiti
        End Get
        Set(ByVal Value As DataTable)
            _requisiti = Value
        End Set
    End Property

    Public Sub carica()
        Dim dr As DataRow = getDataTable("select convert(char(10),data,103) as  data, idIstituto,matricola, tipo, motivo, convert(char(10),data_pub,103) as data_pub, note from specializzazioni where id=" & _id).Rows(0)

        _data = Utility.sNull(dr("data"))
        _matricola = Utility.sNull(dr("matricola"))
        _tipo = Utility.sNull(dr("tipo"))
        _motivo = Utility.sNull(dr("motivo"))
        _dataPub = Utility.sNull(dr("data_pub"))
        _note = Utility.sNull(dr("note"))
        _idIstituto = Utility.sNull(dr("idIstituto"))

        _requisiti = getDataTable("SELECT Requisiti.codice, Requisiti.descrizione FROM Requisiti INNER JOIN SpecRequisiti ON Requisiti.codice = SpecRequisiti.idRequisito WHERE SpecRequisiti.idSpec = " & _id)

    End Sub

    Public Sub salva()
        If _id = "" Then
            _id = eseguiSPInsert("insertSpec")
        End If
        aggiorna()

    End Sub


    Private Sub aggiorna()
        Dim sql As String = "update Specializzazioni set idIscritto=@idIsc, data=@data, matricola=@matricola, tipo=@tipo, motivo=@motivo, data_pub = @dataPub, note=@note, idIstituto=@idIstituto, utente=@utente where id=" & _id
        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(sql, getConnection)
        cmd.Parameters.Add("@idIsc", _idIsc)
        cmd.Parameters.Add("@data", IIf(_data = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_data)))
        cmd.Parameters.Add("@dataPub", IIf(_dataPub = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_dataPub)))
        cmd.Parameters.Add("@matricola", _matricola)
        cmd.Parameters.Add("@tipo", IIf(_tipo = "", SqlTypes.SqlInt16.Null, _tipo))
        cmd.Parameters.Add("@motivo", IIf(_motivo = "", SqlTypes.SqlInt16.Null, _motivo))
        cmd.Parameters.Add("@note", _note)
        cmd.Parameters.Add("@idIstituto", IIf(Utility.StringIsNullOrEmpty(_idIstituto), SqlTypes.SqlString.Null, _idIstituto))
        cmd.Parameters.Add("@Utente", System.Security.Principal.WindowsIdentity.GetCurrent.Name)
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

        eseguiSql("delete from specRequisiti where idSpec =" & _id)

        Dim dr As DataRow
        For Each dr In _requisiti.Rows
            eseguiSql("insert into specRequisiti (idRequisito, idSpec) values (" & dr("codice") & ", " & _id & ")")
        Next

    End Sub

    Public Sub elimina()
        eseguiSql("delete from specializzazioni where id=" & _id)
    End Sub

End Class


Public Class cAttivita
    Inherits Connessione

    Private _id As String
    Private _idIsc As String
    Private _att As String
    Private _dal As String
    Private _al As String
    Private _settore As String

    Public Property id() As String
        Get
            Return _id
        End Get
        Set(ByVal Value As String)
            _id = Value
        End Set
    End Property
    Public Property idIsc() As String
        Get
            Return _idIsc
        End Get
        Set(ByVal Value As String)
            _idIsc = Value
        End Set
    End Property
    Public Property att() As String
        Get
            Return _att
        End Get
        Set(ByVal Value As String)
            _att = Value
        End Set
    End Property
    Public Property dal() As String
        Get
            Return _dal
        End Get
        Set(ByVal Value As String)
            _dal = Value
        End Set
    End Property
    Public Property al() As String
        Get
            Return _al
        End Get
        Set(ByVal Value As String)
            _al = Value
        End Set
    End Property
    Public Property settore() As String
        Get
            Return _settore
        End Get
        Set(ByVal Value As String)
            _settore = Value
        End Set
    End Property


    Public Sub carica()
        Dim dr As DataRow = getDataTable("select convert(char(10),dal,103) as  dal, convert(char(10),al,103) as  al, " & _
                " attivita, settore from attPeriti where id=" & _id).Rows(0)

        _dal = Utility.sNull(dr("dal"))
        _al = Utility.sNull(dr("al"))
        _att = Utility.sNull(dr("attivita"))
        _settore = Utility.sNull(dr("settore"))

    End Sub

    Public Sub salva()
        If _id = "" Then
            inserisci()
        Else
            aggiorna()
        End If
    End Sub

    Private Sub aggiorna()
        Dim sql As String = "update attPeriti set dal = @dal, al=@al, attivita=@att, settore=@settore where id=" & _id
        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(sql, getConnection)
        cmd.Parameters.Add("@dal", IIf(_dal = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_dal)))
        cmd.Parameters.Add("@al", IIf(_al = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_al)))
        cmd.Parameters.Add("@att", IIf(_att = "", SqlTypes.SqlInt16.Null, _att))
        cmd.Parameters.Add("@settore", IIf(_settore = "", SqlTypes.SqlInt16.Null, _settore))
        cmd.Parameters.Add("@Utente", System.Security.Principal.WindowsIdentity.GetCurrent.Name)
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
    End Sub

    Private Sub inserisci()
        Dim sql As String = "insert into attPeriti (id_isc, dal, al, attivita, settore, utente) values (" & _
                "@idIsc, @dal, @al, @att, @settore,@utente)"
        Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(sql, getConnection)
        cmd.Parameters.Add("@idIsc", _idIsc)
        cmd.Parameters.Add("@dal", IIf(_dal = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_dal)))
        cmd.Parameters.Add("@al", IIf(_al = "", SqlTypes.SqlDateTime.Null, Utility.FormattaDataxDB(_al)))
        cmd.Parameters.Add("@att", IIf(_att = "", SqlTypes.SqlInt16.Null, _att))
        cmd.Parameters.Add("@settore", IIf(_settore = "", SqlTypes.SqlInt16.Null, _settore))
        cmd.Parameters.Add("@Utente", System.Security.Principal.WindowsIdentity.GetCurrent.Name)
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
    End Sub

    Public Sub elimina()
        eseguiSql("delete from attperiti where id=" & _id)
    End Sub


End Class